import AsyncStorage from '@react-native-async-storage/async-storage';
export const setStorageItem = async (key: string, value: string) => {
  return await AsyncStorage.setItem(key, value);
};
export const getStorageItem = async (key: string) => {
  return await AsyncStorage.getItem(key);
};

// 判断应用是否首次安装
async function isFirstTimeInstallation() {
  try {
    const isFirstTime = await AsyncStorage.getItem('isFirstTime');
    if (isFirstTime === null) {
      // 如果是首次安装，设置标志位为 false
      await AsyncStorage.setItem('isFirstTime', 'false');
      return true;
    } else {
      return false;
    }
  } catch (error) {
    console.error('Error checking first time installation:', error);
    return false;
  }
}
export async function checkInstallation() {
  const isFirstTime = await isFirstTimeInstallation();
  if (isFirstTime) {
    console.log('This is the first time the app is being installed.');
    AsyncStorage.setItem(
      'dragData',
      JSON.stringify([
        {
          value: {
            dragBg: {
              bgColor: '#ffffff',
              radius: 0,
              cover: true,
            },
            dragList: [
              {
                id: 1713091477000,
                type: 'text',
                text: '某某公司',
                color: '#000000',
                fontSize: 48,
                textAlign: 'center',
                width: 200,
                height: 50,
                active: false,
                fontFamily: 'ALiDaKai',
                top: 50,
                left: 85.5,
                radius: 0,
                zIndex: 1,
              },
              {
                id: 1713091500000,
                type: 'text',
                text: '姓名：',
                color: '#000000',
                fontSize: 44,
                textAlign: 'center',
                width: '151',
                height: '46',
                active: false,
                fontFamily: 'ALiDaKai',
                top: 192,
                left: 18.5,
                radius: 0,
                zIndex: 2,
              },
              {
                id: 1713091519000,
                type: 'text',
                text: '部门：',
                color: '#000000',
                fontSize: 44,
                textAlign: 'center',
                width: '153',
                height: '42',
                active: false,
                fontFamily: 'ALiDaKai',
                top: 263,
                left: 18,
                radius: 0,
                zIndex: 3,
              },
              {
                id: 1713091555000,
                type: 'text',
                text: '工号：',
                color: '#000000',
                fontSize: 43,
                textAlign: 'center',
                width: '141',
                height: '48',
                active: false,
                fontFamily: 'ALiDaKai',
                top: 335.5,
                left: 18,
                radius: 0,
                zIndex: 4,
              },
              {
                id: 1713091573000,
                type: 'text',
                text: '张三丰',
                color: '#000000',
                fontSize: 44,
                textAlign: 'center',
                width: '182',
                height: '46',
                active: false,
                fontFamily: 'ALiDaKai',
                top: 186,
                left: 145,
                radius: 0,
                zIndex: 5,
              },
              {
                id: 1713091589000,
                type: 'text',
                text: '生产部',
                color: '#000000',
                fontSize: 45,
                textAlign: 'center',
                width: '178',
                height: '48',
                active: false,
                fontFamily: 'ALiDaKai',
                top: 261,
                left: 141,
                radius: 0,
                zIndex: 6,
              },
              {
                id: 1713091605000,
                type: 'text',
                text: '10001',
                color: '#000000',
                fontSize: 43,
                textAlign: 'center',
                width: '163',
                height: '46',
                active: true,
                fontFamily: 'ALiDaKai',
                top: 333.5,
                left: 139.5,
                radius: 0,
                zIndex: 7,
              },
            ],
          },
          name: '模板01',
          id:new Date().valueOf()
        },
      ]),
    );
  } else {
    console.log('The app has been installed before.');
  }
}

// 使用示例
